(function(){

// 渲染商品页面
fetch("http://chst.vip:1234/api/getmoneyctrl?pageid=0")
.then(body=>body.json())
.then(res=>{
    // console.log(res);


    // 获取页面元素个数
    let totalCount = res.totalCount;
    // console.log(totalCount);

    // 得到一共多少页面
    let math =Math.ceil(totalCount/10);   //向上取整
    // console.log(math);



    // 动态添加页面页数


    body=""
    for (var i=1;i<=math;i++){
        // console.log(i);
        body+=
        `
        <option value="${i-1}">${i}/${math}</option>
        `

    }
  $('#select').append(body)

  $('.btn1').prop('disabled',true).css({background:'gray'})





    let html = "";
    res.result.forEach(item=>{
        html+=
        `<li productid=${item.productId}>
        <a href="#">
            <div class="img">${item.productImgSm}</div>
            <div class="infoR">
                <div class="title">
                    <h4>${item.productName}
                    </h4>
                </div>
                <div class="other">
                    <span class="diyi">${item.productFrom} |${item.productTime}</span>
                    <span class="dier">
                        <i><img src="/assets/images/QQ-1.jpg" alt=""></i>
                        <span>${item.productComCount}</span>
                    </span>
                </div>
            </div>
        </a>
    </li>
        `
    })
    $('#product ul').html(html)

    let lis= [...$('#product ul li')]


        lis.forEach(li=>{
            // console.log(li);
            li.onclick=function(){
                let productid=this.getAttribute('productid')
                // console.log(productid);
                // console.log(123);
                location.href =`../pages/dateli.html?productid=${productid}`
            }
        })

})

let a = 0

$('.btn2').click(function(){
    // 下一页
    a++
    console.log(a);
    fn1(a)
})


$('.btn1').click(function(){
    // 上一页
    a--
    console.log(a);
    fn1(a)
})


$('#select').change(function(){
    a = $('#select').val()
    console.log(a);
    fn1(a)

})
















function fn1(a){

    fetch(`http://chst.vip:1234/api/getmoneyctrl?pageid=${a}`)
    .then(body=>body.json())
    .then(res=>{
        // console.log(res);
        $('#select').val(a)
    
        // 获取页面元素个数
        let totalCount = res.totalCount;
        // console.log(totalCount);
    
        // 得到一共多少页面
        let math =Math.ceil(totalCount/10);   //向上取整
        // console.log(math);
    
    
    
        // 动态添加页面页数
    
    
    //     body=""
    //     for (var i=1;i<=math;i++){
    //         // console.log(i);
    //         body+=
    //         `
    //         <option value="${i-1}">${i}/${math}</option>
    //         `
    
    //     }
    //   $('#select').append(body)
    
    //   $('.btn1').prop('disabled',true).css({background:'gray'})
    
    
    
    
    
        let html = "";
        res.result.forEach(item=>{
            html+=
            `<li productid=${item.productId}>
            <a href="#">
                <div class="img">${item.productImgSm}</div>
                <div class="infoR">
                    <div class="title">
                        <h4>${item.productName}
                        </h4>
                    </div>
                    <div class="other">
                        <span class="diyi">${item.productFrom} |${item.productTime}</span>
                        <span class="dier">
                            <i><img src="/assets/images/QQ-1.jpg" alt=""></i>
                            <span>${item.productComCount}</span>
                        </span>
                    </div>
                </div>
            </a>
        </li>
            `
        })
        $('#product ul').html(html)


            let lis= [...$('#product ul li')]
    
    
            lis.forEach(li=>{
                // console.log(li);
                li.onclick=function(){
                    let productid=this.getAttribute('productid')
                    // console.log(productid);
                    // console.log(123);
                    location.href =`../pages/dateli.html?productid=${productid}`
                }
            })


        
        if(a==0){
        
            $('.btn1').prop('disabled',true).css({background:'gray'})
        }else if(a>0){
        
          $('.btn1').prop('disabled',false).css({background:'orange'})
        }


        if(a==(math-1)){
        //  console.log(a);
            $('.btn2').prop('disabled',true).css({background:'gray'})
        }else if(a<math){
        
          $('.btn2').prop('disabled',false).css({background:'orange'})
        }
    
       
    
    })


}





})()